<style>
    #sp
    {
        width:32.3%;
        float:left;
        height:300px;
        background:#eee;
        border-color:#CCC;
        border-style:inset;
        text-align:center;
    }
</style>
<?php
function tinh_gia_dau__yyy()
{
    $gia_dau=$_GET['gia_dau'];
    if($gia_dau=="Giá đầu" or $gia_dau=="")
    {
        $gia_dau=0;
    }
    if($gia_dau <0)
    {
        $gia_dau=0;
    }
    return $gia_dau;
}
function tinh_gia_cuoi__yyy()
{
    $gia_cuoi=$_GET['gia_cuoi'];
    if($gia_cuoi=="Giá cuối" or $gia_cuoi=="")
    {
        $gia_cuoi=99999999999;
    }
    if($gia_cuoi<0)
    {
        $gia_cuoi=99999999999;
    }
    return $gia_cuoi;
}
?>
<?php
$tu_khoa=$_GET['tu_khoa'];
$gia_dau=tinh_gia_dau__yyy();
$gia_cuoi=tinh_gia_cuoi__yyy();
$mang_tk=explode(" ",$tu_khoa);	//cắt chuổi từ khóa thành mảng.
$sql="";	// lưu câu lệnh sql
for($f=0;$f<count($mang_tk);$f++)
{
    $q=$mang_tk[$f];
    if($q!="" and $_GET['tu_khoa']!="Từ khóa")
    {
        $sql=$sql." tensp like '%$q%' or";
    }
}
$sql=substr($sql,0,-3);	//xóa 3 ký tự cuối chuổi.
if($_GET['tu_khoa']!="Từ khóa")
{
    $sql="(".$sql.")";
    $sql=$sql." and ";
}
$sql=$sql." gia between $gia_dau and $gia_cuoi";
//thongbao($sql);
    echo "<table border='0' width='100%'>";
        echo "<tr>";
            echo "<td width='100%'>";
            $sql="select * from dm_sanpham where $sql group by idsp desc";
            $data=mysql_query($sql);
            while ($row=mysql_fetch_array($data))
            {
                $link="?thamso=tt&idsp=$row[idsp]";
                echo "<div id='sp'>";
                    echo "<div style='height:50px';>";
                        echo "<font size='3' color='#FF0000'><a href='$link'>".$row['tensp']."</a></font><br>";
                    echo "</div>";
                echo "<a href='$link'><img src='image/ha_sp/".$row['hinh']."' border='0' width='150px' height='150px'></a><br>";
                $dinh_dang_gia=number_format($row['gia'],0,".",".");
                echo "<font size='3' color='#FF0000'><b>".$dinh_dang_gia." VND</b></font><br>";
                echo "<form action='' method=''>";
                    echo "<font size='3' color='#0000FF'>Còn: ".$row['soluong'] ."</font>" ."<br>";
                        echo "<font size='3' color='#0000FF'>Số lượng : ";
                        echo "<input style='width:50px' value='1' name='so_luong'  onKeyPress='if((event.keyCode< 48)|| (event.keyCode > 57)) event.returnValue =false'></font>";
                        echo "<br>";
                        echo "<div style='overflow:hidden;width:5px;height:3px'></div>";
                        echo "<input type='hidden' name='id_sp__nnn' value='$row[idsp]'>";
                        echo "<input type='hidden' name='them_vao_gio' value='them_vao_gio'>";
                        echo "<input type='image' src='image/chung/mua.gif' style='border:0px solid red'>";
                echo "</form>";
            echo "</div>";
            }
        echo "</td>";
    echo "</tr>";
echo "</table>";
?>